/*
 * @Author: ShiJunJie
 * @Date: 2022-04-01 14:33:50
 * @LastEditors  : ShiJunJie
 * @LastEditTime : 2022-04-20 11:41:03
 * @Descripttion: 
 */
/**
 * 插件功能：从 src/views 目录自动生成文件路由
 */
import type { App } from 'vue';
import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router';
import { createRoutes, createGuard } from './guards';

import basicRoutes from 'virtual:generated-pages';
const routes = createRoutes(basicRoutes);

/* @__PURE__ */
console.log('项目路由组', routes);

export const router = createRouter({
  history: import.meta.env.VITE_HTTP_HASH === true ? createWebHashHistory() : createWebHistory(import.meta.env.VITE_APP_BASE_URL || '/'),
  scrollBehavior: () => ({ el: '*', top: 0 }),
  routes
})

export default async (app: App) => {
  app.use(router)
  await createGuard(router)
  await router.isReady()
}
